<?php

if (!defined('MODULE_FILE')){
	die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );
?>
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="js/Autocomplete/resources/css/smoothness/jquery-ui-1.10.1.custom.css"/>
	<link rel="stylesheet" type="text/css" media="screen" href="js/Autocomplete/resources/css/smoothness/jquery.ui.combogrid.css"/>
	<link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
	
	<script type="text/javascript" src="js/Autocomplete/resources/jquery/jquery-ui-1.10.1.custom.min.js"></script>
	<script type="text/javascript" src="js/Autocomplete/resources/plugin/jquery.ui.combogrid-1.6.3.js"></script>
	<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
	<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
	<script src="js/bootstrap-confirmation.js" type="text/javascript"></script>
<style type="text/css">
	.cg-menu {
		width: 400px;
	}
	
	.cg-menu-item {
		height: 34px;
		font-size: 17px;
	}
	.cg-comboButton {
		height: 50px;
		font-size: 20px;
	}
</style>
</head>
<body>
<br>
<div class="col-lg-10">
	<div class="panel panel-primary">
		<div id="wait" style="display:none; background-color: gray; text-align:center; width:100px;height:120px;border:1px solid black;position:absolute;top:50%;left:50%;padding:2px;"><img src='images/loading.gif' width="64" height="64" /><br><label style="color: blue;">Loading.....</label></div>
		<div class="panel-body">
			<form METHOD="POST" action="modules.php?file=insert_lab_case_paper&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
					<div style="float: left;">
						Patient ID:-<input type="text" value="106" name="patient_details" id="patient_details" style="width: 400px;" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true" placeholder="ID or Patient Name...." /> <input type="button" name="search" value="Search" onclick="searchPatient();" class="btn btn-danger" style="width: 100px;" />
						<input type="hidden" value="" name="patient_id" id="patient_id" />
						<input type="hidden" value="" name="case_paper_id" id="case_paper_id" />
					</div>
					
					<div style="display: none;" id="success_display">
						<img alt="Patient Found with info.." src="images/green_tick.gif" width="40" height="40">
						<label id='disp_patient_name'></label>
					</div>
					<div style="display: none;" id="failed_display">
						<img alt="Patient Found with info.." src="images/delete.png" width="40" height="40">
						<label id='disp_failed'></label>
					</div>
					<div style="clear: both;"></div>
					
					<div id="patient_info"></div>
					
					<hr style="border-bottom: 1 none; border-top: 3px solid #009efe; margin-bottom: 0px; margin-top: 0px;"/>
					
					<div id="investigation_data" style="display:none; border-style: dotted; margin: 8px 5px 5px 5px; padding: 5px;">
						<div>
							<label id="lbl_blood_test" style="display: none;" ><input type="checkbox" class="lab_test_reports" name="blood_test" id="blood_test" value="" />&nbsp; Blood Test &nbsp;&nbsp;</label>
							<label id="lbl_x_ray_test" style="display: none;"><input type="checkbox" class="lab_test_reports" name="x_ray_test" id="x_ray_test" value="" />&nbsp; X-Ray &nbsp;&nbsp;</label>
							<label id="lbl_urine_test" style="display: none;"><input type="checkbox" class="lab_test_reports" name="urine_test" id="urine_test" value="" />&nbsp; Urine &nbsp;&nbsp;</label>
							<label id="lbl_sonography_test" style="display: none;"><input type="checkbox" class="lab_test_reports" name="sonography_test" id="sonography_test" value="" />&nbsp; Sonography &nbsp;&nbsp;</label>
							<label id="lbl_widal_reaction_test" style="display: none;"><input type="checkbox" class="lab_test_reports" name="widal_reaction_test" id="widal_reaction_test" value="" />&nbsp; Widal Reaction &nbsp;&nbsp;</label>
							<label id="lbl_others_test" style="display: none;"><input type="checkbox" class="lab_test_reports" name="others_test" id="others_test" value="" />&nbsp; Others &nbsp;&nbsp;</label>
						</div>
					</div>
					<div id="x_ray_from" style="display: none;"></div>
					<hr style="border-bottom: 1 none; border-top: 3px solid #009efe; margin-bottom: 0px; margin-top: 0px;"/>
					
					<div id="blood_from" style="display: none;"></div>
					<hr style="border-bottom: 1 none; border-top: 3px solid #009efe; margin-bottom: 0px; margin-top: 0px;"/>
					
					<div id="urine_from" style="display: none;"></div>
					<hr style="border-bottom: 1 none; border-top: 3px solid #009efe; margin-bottom: 0px; margin-top: 0px;"/>
					
					<div id="sonography_from" style="display: none;"></div>
					<hr style="border-bottom: 1 none; border-top: 3px solid #009efe; margin-bottom: 0px; margin-top: 0px;"/>
					
					<div id="widal_reaction_from" style="display: none;"></div>
					<hr style="border-bottom: 1 none; border-top: 3px solid #009efe; margin-bottom: 0px; margin-top: 0px;"/>
					
					<div id="others_from" style="display: none;"></div>
			</form>
		</div>
</div>
</div>	
</body>
</html>

<script>
	var intCasePaperId = '';
	$(document).ready(function(){
		$( "#from" ).datepicker({
			dateFormat: 'yy-mm-dd',
			showOn: "button",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true,
			changeMonth: true,
			changeYear: true,
			yearRange: "-30"
		});
	});

	jQuery(document).ready(function(){
		$( "#patient_details" ).combogrid({
			url: 'modules.php?file=fetch_server&type=fetch&action=serachPatientByCasePaper',
			debug:true,
			//replaceNull: true,
			colModel: [{'columnName':'id','width':'10','label':'Id'}, {'columnName':'name','width':'60','label':'Full Name'},{'columnName':'case_paper_id','width':'30','label':'Case Paper Id'}],
			select: function( event, ui ) {
				$( "#patient_details" ).val( ui.item.name );
				$( "#patient_id" ).val( ui.item.id );
				$( "#case_paper_id" ).val( ui.item.case_paper_id );
				return false;
				}
		});
	});

	function searchPatient() {

		var intPatientId =	parseInt( $('#patient_details').val() );

		if( false == $.isNumeric( intPatientId ) || true == isNaN( intPatientId ) ) {
			intPatientId =	$('#patient_id').val();
		}

		$strUrl = "modules.php?file=search_patient&type=search&patient_id=" + intPatientId;

		$.ajax({
			url: $strUrl,
			type: "post",
			data: "patient_data=" + intPatientId,
			success: function( returnData ) {
				strCustomerData = returnData;
		
				if( 'not found::' == strCustomerData ) {
					$( '#failed_display' ).css( "display", "block" );
					$( '#disp_failed' ).html( "Patient not found with :: " + $('#patient_details').val() );
					$( '#success_display' ).css( "display", "none" );
					$( '#patient_id' ).val( '' );
					$( '#case_paper_id' ).val( '' );

					$('#investigation_data').hide( 'slow' );
					
					$( '#patient_info' ).html( '' );
					$( '#patient_info' ).css( "display", "none" );
				} else {
					$( '#failed_display' ).css( "display", "none" );
					$( '#success_display' ).css( "display", "block" );
					var strData = strCustomerData.split( '_' );
					$( '#disp_patient_name' ).html( "(" + strData[0] + ") " + strData[1] + " " + strData[2] );
					$( '#patient_id' ).val( strData[0] );
					$( '#case_paper_id' ).val( strData[3] );
					intCasePaperId = strData[3];

					$('#investigation_data').show( 'slow' );

					displayPatientInfo( strData[0] );
					loadInvetigation( intCasePaperId );
				}
			},
			error:function(){
				alert( "! Patient not found with provided information, Please check entered data of patient." );
			}
		});
	}

	function displayPatientInfo( intPatientId ) {

		$strUrl = 'modules.php?file=patient_info&type=search&patient_id=' + intPatientId;
		
		$.ajax({
			url: $strUrl,
			type: "post",
			data: "patient_data=" + intPatientId,
			success: function( returnData ) {
				strPatientData = returnData;
		
				if( 'not found::' == strPatientData ) {
					$( '#patient_info' ).html( '' );
					$( '#patient_info' ).css( "display", "none" );
				} else {
					$( '#patient_info' ).html( strPatientData );
					$( '#patient_info' ).css( "display", "block" );
				}
			},
			error:function(){
				alert( "! Patient not found with provided information, Please check entered data of patient." );
			}
		});
	}

	function loadInvetigation( intCasePaperId ) {

		var intPatientId 	=	$('#patient_id').val();

		var getParams={ patient_id:intPatientId };
		 
		$.getJSON( 'modules.php?file=fetch_investigration_details&type=fetch&case_paper_id=' + intCasePaperId + '&patint_id=' + intPatientId, getParams,

		function( data ) {
			if( data != '' ) {
				for( var i =0; i<= data.length; i++ ) {
					$('#lbl_' + data[i] ).show();
				}
			} else {
				$('#lbl_blood_test').hide();
				$('#lbl_x_ray_test').hide();
				$('#lbl_urine_test').hide();
				$('#lbl_sonography_test').hide();
				$('#lbl_widal_reaction_test').hide();
				$('#lbl_others_test').hide();
			}
		});
	}

	$("#x_ray_test").change( function() {

		var intPatientId 	=	$('#patient_id').val();
		var intCasePaperId 	=	$('#case_paper_id').val();

		if( true == $(this).is(":checked") ) {
			$strUrl = "modules.php?file=x-ray_test&type=forms&patient_id=" + intPatientId + "&case_paper_id=" + intCasePaperId;
	
			$.ajax({
				url: $strUrl,
				type: "post",
				data: "patient_data=" + intPatientId,
				beforeSend: function() {
					$("#wait").css("display","block");
					$('.col-lg-10').css("display","none");
				},
				success: function( returnData ) {
					strCustomerData = returnData;
					$('#x_ray_from' ). html( strCustomerData );
					$( "#x_ray_from" ).show( 300 );

					$("#wait").css("display","none");
					$('.col-lg-10').css("display","block");
				},
				error:function(){
					alert( "! Patient not found with provided information, Please check entered data of patient." );
				}
			});
		} else {
			$('#x_ray_from' ). html( '' );
			$( "#x_ray_from" ).hide( 300 );
		}
	});

	$("#blood_test").change( function() {

		var intPatientId 	=	$('#patient_id').val();
		var intCasePaperId 	=	$('#case_paper_id').val();

		$(this).delay( 8000 );

		if( true == $(this).is(":checked") ) {
			$strUrl = "modules.php?file=blood_test&type=forms&patient_id=" + intPatientId + "&case_paper_id=" + intCasePaperId;
	
			$.ajax({
				url: $strUrl,
				type: "post",
				data: "patient_data=" + intPatientId,
				beforeSend: function() {
					$("#wait").css("display","block");
					$('.col-lg-10').css("display","none");
				},
				success: function( returnData ) {
					strCustomerData = returnData;
					$('#blood_from' ).html( strCustomerData );
					$( "#blood_from" ).show( 300 );

					$("#wait").css("display","none");
					$('.col-lg-10').css("display","block");
				},
				error:function(){
					alert( "! Patient not found with provided information, Please check entered data of patient." );
				}
			});
		} else {
			$('#blood_from' ). html( '' );
			$( "#blood_from" ).hide( 300 );
		}
	});

	$("#urine_test").change( function() {

		var intPatientId 	=	$('#patient_id').val();
		var intCasePaperId 	=	$('#case_paper_id').val();

		$(this).delay( 8000 );

		if( true == $(this).is(":checked") ) {
			$strUrl = "modules.php?file=urine_test&type=forms&patient_id=" + intPatientId + '&case_paper_id=' + intCasePaperId;
	
			$.ajax({
				url: $strUrl,
				type: "post",
				data: "patient_data=" + intPatientId,
				beforeSend: function() {
					$("#wait").css("display","block");
					$('.col-lg-10').css("display","none");
				},
				success: function( returnData ) {
					strCustomerData = returnData;
					$('#urine_from' ).html( strCustomerData );
					$( "#urine_from" ).show( 300 );

					$("#wait").css("display", "none");
					$('.col-lg-10').css("display", "block");
				},
				error:function(){
					alert( "! Patient not found with provided information, Please check entered data of patient." );
				}
			});
		} else {
			$('#urine_from' ). html( '' );
			$( "#urine_from" ).hide( 300 );
		}
	});

	$("#sonography_test").change( function() {

		var intPatientId 	=	$('#patient_id').val();
		var intCasePaperId 	=	$('#case_paper_id').val();

		$(this).delay( 8000 );

		if( true == $(this).is(":checked") ) {
			$strUrl = "modules.php?file=sonography_test&type=forms&patient_id=" + intPatientId + "&case_paper_id=" + intCasePaperId;
	
			$.ajax({
				url: $strUrl,
				type: "post",
				data: "patient_data=" + intPatientId,
				beforeSend: function() {
					$("#wait").css("display","block");
					$('.col-lg-10').css("display","none");
				},
				success: function( returnData ) {
					strCustomerData = returnData;
					$('#sonography_from' ).html( strCustomerData );
					$( "#sonography_from" ).show( 300 );

					$("#wait").css("display", "none");
					$('.col-lg-10').css("display","block");
				},
				error:function(){
					alert( "! Patient not found with provided information, Please check entered data of patient." );
				}
			});
		} else {
			$('#sonography_from' ). html( '' );
			$( "#sonography_from" ).hide( 300 );
		}
	});

	$("#widal_reaction_test").change( function() {

		var intPatientId 	=	$('#patient_id').val();
		var intCasePaperId 	=	$('#case_paper_id').val();

		$(this).delay( 8000 );

		if( true == $(this).is(":checked") ) {
			$strUrl = "modules.php?file=widal_reaction_test&type=forms&patient_id=" + intPatientId;
	
			$.ajax({
				url: $strUrl,
				type: "post",
				data: "patient_data=" + intPatientId,
				beforeSend: function() {
					$("#wait").css("display","block");
					$('.col-lg-10').css("display","none");
				},
				success: function( returnData ) {
					strCustomerData = returnData;
					$('#widal_reaction_from' ).html( strCustomerData );
					$( "#widal_reaction_from" ).show( 300 );

					$("#wait").css("display","none");
					$('.col-lg-10').css("display", "block");
				},
				error:function(){
					alert( "! Patient not found with provided information, Please check entered data of patient." );
				}
			});
		} else {
			$('#widal_reaction_from' ). html( '' );
			$( "#widal_reaction_from" ).hide( 300 );
		}
	});

	$("#others_test").change( function() {

		var intPatientId 	=	$('#patient_id').val();

		$(this).delay( 8000 );

		if( true == $(this).is(":checked") ) {
			$strUrl = "modules.php?file=others_test&type=forms&patient_id=" + intPatientId;
	
			$.ajax({
				url: $strUrl,
				type: "post",
				data: "patient_data=" + intPatientId,
				beforeSend: function() {
					$("#wait").css("display","block");
					$('.col-lg-10').css("display","none");
				},
				success: function( returnData ) {
					strCustomerData = returnData;
					$('#others_from' ).html( strCustomerData );
					$( "#others_from" ).show( 300 );

					$("#wait").css("display","none");
					$('.col-lg-10').css("display","block");
				},
				error:function(){
					alert( "! Patient not found with provided information, Please check entered data of patient." );
				}
			});
		} else {
			$('#others_from' ). html( '' );
			$( "#others_from" ).hide( 300 );
		}
	});

	$( '.lab_test_reports' ).change( function() {
		objThis = $(this);
		$( '.lab_test_reports' ).each( function() {
			if( objThis.attr('id') != $(this).attr('id') ) {
				$(this).attr( 'checked', false );
				strIdName = $(this).attr('id').replace( 'test', 'from' );
				$('#' + strIdName ).html( '' );
			}
		});
	});

</script>